﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace LogCat.Utility
{
    class IOUtility
    {
        static string Tag = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName;

        //应用数据的存储位置
        public static string DataPath{
            get{
                string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/LogCat/";
                CreateFolder(path);
                return path;
            }
        }

        //创建文件夹
        public static bool CreateFolder(string path) {

            if(Directory.Exists(path)){
                return true;
            }

            try {
                Directory.CreateDirectory(path);
            }catch(Exception e){
                Log.e(Tag,e.Message);
                return false;
            }

            return true;
        }

        //删除文件或文件夹
        public static bool DeleteFile(string path) {

            try 
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                if (Directory.Exists(path))
                {
                    DirectoryInfo dir = new DirectoryInfo(path);
                    dir.Delete(true);
                }            
            }
            catch(Exception e)
            {
                Log.e(Tag, e.Message);
                return false;
            }

            return true;
        }
    }
}
